﻿//  Copyright (c) 2010 Ray Liang (http://www.dotnetage.com)
//  Dual licensed under the MIT and GPL licenses:
//  http://www.opensource.org/licenses/mit-license.php
//  http://www.gnu.org/licenses/gpl.html

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Mvc;

namespace DNA.Mvc.jQuery
{
    //public class TemplateViewBuilder<TComponent> : ViewComponentBuilder<TComponent, TemplateViewBuilder<TComponent>>
    //    where TComponent : TemplateViewComponent<object>
    //{
    //    public TemplateViewBuilder(TComponent component, ViewContext viewContext, IViewDataContainer viewContainer) : base(component, viewContext, viewContainer) { }
    //}

    public class TemplateViewBuilder<TComponent> : TemplateViewBuilder<TComponent, TemplateViewBuilder<TComponent>>
        where TComponent : TemplateViewComponent
    {
        public TemplateViewBuilder(TComponent component, ViewContext viewContext, IViewDataContainer viewContainer) : base(component, viewContext, viewContainer) { }
    }

    public class TemplateViewBuilder<TComponent, TBuilder> : ViewComponentBuilder<TComponent, TBuilder>
        where TComponent : TemplateViewComponent
        where TBuilder : TemplateViewBuilder<TComponent, TBuilder>
    {
        public TemplateViewBuilder(TComponent component, ViewContext viewContext, IViewDataContainer viewContainer) : base(component, viewContext, viewContainer) { }

        public TBuilder Template(Action value)
        {
            Component.Template.Content = value;
            return this as TBuilder;
        }

        public TBuilder Template(Func<object, object> value)
        {
            this.Component.Template.InlineContent = value;
            return this as TBuilder;
        }
    }

    public class TemplateViewBuilder<TModel, TComponent, TBuilder> : ViewComponentBuilder<TComponent, TBuilder>
        where TModel : class
        where TComponent : TemplateViewComponent<TModel>
        where TBuilder : TemplateViewBuilder<TModel, TComponent, TBuilder>
    {
        public TemplateViewBuilder(TComponent component, ViewContext viewContext, IViewDataContainer viewContainer) : base(component, viewContext, viewContainer) { }

        public TBuilder Template(Func<TModel, object> value)
        {
            this.Component.Template.InlineContent = value;
            return this as TBuilder;
        }

        public virtual TBuilder Template(Action<TModel> value)
        {
            this.Component.Template.Content = value;
            return this as TBuilder;
        }
    }
}